<script setup>
//引入api
import {queryUserPage} from '@/api/user'
import { onMounted,ref } from 'vue'

//表单参数
const queryForm =ref({
  page:1,
  pageSize:5,
  pages:1,
  total:0,
  body:{
    name:'',
    gender:''
  }
})
//数据列表
const userList=ref([])
//定义方法实现分页查询
const queryUsers=async()=>{
 let result=await queryUserPage(queryForm.value)
 console.log(result)
 userList.value=result.data
 //分页数据
 queryForm.value.pages=result.pages
 queryForm.value.total=result.total
}
//每页条数发生变化
const handleSizeChange = (val) => {
  queryForm.value.page=1
 queryForm.value.pageSize=val
 queryUsers()
}
//当前页发生变化的条数
const handleCurrentChange = (val) => {
  queryForm.value.page=val
 queryUsers()
}

//预加载
onMounted(()=>{
  queryUsers()

})
</script>

<template>
  <!-- 表单数据 -->
  <el-form :inline="true" :model="queryForm" class="demo-form-inline">
    <el-form-item label="姓名">
      <el-input v-model="queryForm.body.name" placeholder="姓名" clearable />
    </el-form-item>
    <el-form-item label="性别">
      <el-select
        v-model="queryForm.body.gender"
        placeholder="性别"
        clearable
      >
        <el-option label="男" value="1" />
        <el-option label="女" value="2" />
      </el-select>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="queryUsers">查询</el-button>
    </el-form-item>
  </el-form>
    <!-- 表格数据 -->
      <el-table :data="userList" style="width: 100%">
    <el-table-column prop="id" label="Id" width="100" />
    <el-table-column prop="name" label="Name" width="100" />
    <el-table-column prop="gender" label="gender" >
      <template #default="scope">
        <span v-if="scope.row.gender==1">男</span>
        <span v-else>女</span>       
      </template>
    </el-table-column>
     <el-table-column prop="createTime" label="CreateTime" width="180" />
  </el-table>
  <!-- 分页 -->
   <el-pagination
      v-model:current-page="queryForm.page"
      v-model:page-size="queryForm.pageSize"
      :page-sizes="[5, 10, 15, 20]"
      
      layout="total, sizes, prev, pager, next, jumper"
      :total="queryForm.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange" 
    />
</template>


